'''
1.服装销售管理系统，裙子裤子 服装（父类，名称 类别和库存数量），用户（姓名，余额，消费行为（参数为买的什么服装多少件）{扣除用户余额，减去服装的库存
}）
'''
class Clothes:
    name=''
    price=0
    stocknum=0
    def __init__(self,name,price,stocknum):
        self.name = name
        self.price = price
        self.stocknum = stocknum
class Trouers(Clothes):
    pass
class Skirt(Clothes):
    pass
class Customer:
    name=0
    money=0
    def __init__(self,name,money):
        self.name = name
        self.money = money
    def buy(self,clothes,clotheShop,num):#到服装店买衣服需要告知买什么衣服和买几件,买东西是用户的行为，但是买东西要依靠服装店的销售才能成功
        clotheShop.sell(self,clothes,num)
class ClotheShop:#服装店
    name=''
    # 服装点的销售行为需要知道扣谁的钱，减什么衣服库存，用什么衣服的单价*数量得出总价,
    # 为什么方法需要的参数都有定义成小写的对象实例（实际存在例子），因为真正要销售结账，需要实际的用户信息和衣服
    def sell(self,customer,clothes,num):
        if num >  clothes.stocknum:
            print("库存不足下单失败")
            return
        sum = clothes.price * num
        customer.money = customer.money - sum #剩下的钱等于原来的钱 减去 总消费
        clothes.stocknum = clothes.stocknum - num
        print(customer.name+"用户购买"+clothes.name+str(num)+"件，共消费"+str(sum)+",余额"+str(customer.money))
        print(clothes.name + "库存" + str(clothes.stocknum))
    def addStock(self,clothes,num):
        clothes.stocknum = clothes.stocknum + num

customer=Customer('张三',5000)
trouers=Trouers('jack walk长裤',100,10)
skirt=Skirt('长裙子',50,20)
clotheShop=ClotheShop()
customer.buy(trouers,clotheShop,3)
customer.buy(trouers,clotheShop,3)
customer.buy(trouers,clotheShop,3)
customer.buy(trouers,clotheShop,3)
clotheShop.addStock(trouers,5)
print(trouers.stocknum)
customer.buy(trouers,clotheShop,4)
customer.buy(trouers,clotheShop,4)




